package pers.zh.parking.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.utils.RxLifecycleUtils;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;

import javax.inject.Inject;

import pers.zh.parking.common.BaseObserver;
import pers.zh.parking.common.BaseResponse;
import pers.zh.parking.common.RxScheduler;
import pers.zh.parking.data.entity.User;
import pers.zh.parking.mvp.contract.ModifyPwdContract;

@ActivityScope
public class ModifyPwdPresenter extends BasePresenter<ModifyPwdContract.Model, ModifyPwdContract.View> {

    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    public ModifyPwdPresenter(ModifyPwdContract.Model model, ModifyPwdContract.View rootView) {
        super(model, rootView);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }

    public void modifyPwd(User user) {
        mModel.modifyPwd(user)
              .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
              .compose(RxScheduler.Obs_io_main())
              .subscribe(new BaseObserver<BaseResponse>(mRootView) {
                  @Override
                  public void onSuccess(BaseResponse baseResponse) {
                      mRootView.showMessage("修改成功，请重新登录");
                      mRootView.success();
                  }
              });
    }
}
